package io.github.lee.jel.ui.server.add

import android.content.Context
import android.content.Intent
import androidx.activity.viewModels
import androidx.appcompat.widget.Toolbar
import androidx.core.content.res.ResourcesCompat
import dagger.hilt.android.AndroidEntryPoint
import io.github.lee.core.ui.BaseActivity
import io.github.lee.core.ui.databinding.ToolbarSimpleCenterTitleBinding
import io.github.lee.jel.R
import io.github.lee.jel.databinding.ActivityAddSeverBinding

@AndroidEntryPoint
class AddServerActivity : BaseActivity<ActivityAddSeverBinding, AddServerVM>() {

    companion object {
        @JvmStatic
        fun start(context: Context) {
            val starter = Intent(context, AddServerActivity::class.java)
            context.startActivity(starter)
        }
    }

    override fun onCreateViewModel(): AddServerVM =
        viewModels<AddServerVM>().value

    override fun onCreateToolbar(): Toolbar =
        ToolbarSimpleCenterTitleBinding.inflate(layoutInflater).apply {
            title = getString(R.string.txt_add_jellyfin)
        }.toolbar

    override fun onCreateSuccess(): ActivityAddSeverBinding =
        ActivityAddSeverBinding.inflate(layoutInflater)

    //===Desc:=============================================================

    override fun onObserved() {
        super.onObserved()
        vm?.apply {
            jelLiveData.observe(this@AddServerActivity) {
                if (null == it) {
                    return@observe
                }
                toast(it.toString())
                finish()
            }
        }
    }

    override fun onSetViewData() {
        super.onSetViewData()
        statusBarColor(getColor(R.color.white), true)
        val icon = ResourcesCompat.getDrawable(resources, R.drawable.baseline_close_24, null)
        icon?.setTint(getColor(R.color.main))
        setNavigationIcon(icon) { finish() }

        vb?.vm = vm

    }

}